var mongoose = require('mongoose'),
	PublicEnum = require('./Enum');

//上传文件路径
exports.UploadPath = "./uploads/";
exports.DownloadPath = "./downloads/";
exports.GatewayServer = null;

mongoose.model("Parameter").findOne({Code: 'GatewayServer'}).exec(function(err, record){
	if(!err && record != null){
		var value;
        if(record.Type == PublicEnum.ControlType.TextBox){
            value = record.Value;
        }
        else if(record.Type == PublicEnum.ControlType.CheckBox){
            if(record.Value == 'true'){
                value = true;
            }
            else{
                value = false;
            }
        }
        else if(record.Type == PublicEnum.ControlType.NumberBox){
            value = parseFloat(record.Value);
        }
        else if(record.Type == PublicEnum.ControlType.PercentBox){
            value = parseFloat(record.Value);
        }
        else if(record.Type == PublicEnum.ControlType.DropDownList){
            value = parseInt(record.Value);
        }
        else if(record.Type == PublicEnum.ControlType.Refer){
            value = {
                Key: record.Key,
                Value: record.Value,
                Text: record.Text
            };
        }
        else if(record.Type == PublicEnum.ControlType.Calendar){
            if(record.CalendarType == PublicEnum.DateTimeFormat.Date){
                var date = new Date(record.Value);
                value = new Date(date.getFullYear(), date.getMonth(), date.getDate());
            }
            else{
                value = new Date(record.Value);
            }
        }
        exports.InternalServer = value;
	}
});
